package com.easy.controller;

import com.easy.bean.Member;
import com.easy.service.MemberService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.awt.print.Pageable;

@RestController
@CrossOrigin//允许跨域
@RequestMapping("member")
public class MemberController {

    @Autowired
    MemberService memberService;

    @PostMapping
    public Result add(@RequestBody Member member){
        Object obj=memberService.add(member);
        return Result.success(obj);
    }

    @PutMapping
    public Result edit(@RequestBody Member member){
        Object obj=memberService.edit(member);
        return Result.success("编辑信息保持成功", obj);
    }

    @DeleteMapping("{id}")
    public Result del(@PathVariable("id") Integer id){
        Object obj=memberService.del(id);
        return Result.success("删除成功",obj);
    }

    @GetMapping("{id}")
    public Result one(@PathVariable("id") Integer id){
        Object obj=memberService.one(id);
        return Result.success(obj);
    }

    @GetMapping("all")
    public Result all(Member member){
        Object obj=memberService.all(member);

        return Result.success(obj);
    }
    @GetMapping("page")
    public Result page(Page page,Member member){
        //查询一共有多少条数据
        //当前页要显示的数据
        //将以上数据封装到page对象中
        //返回page对象
        memberService.page(page,member);
        //返回page对象
        return Result.success(page);


    }
}
